package org.uim.cricket.storage;

import java.io.BufferedWriter;
import java.io.FileWriter;

public class FileQueryAppender implements QueryAppendable {

	private String file = null;
	private BufferedWriter writer = null;
	
	public FileQueryAppender(String theFile) {
		file = theFile;
	}
	
	@Override
	public boolean doAppend(String query) throws Exception {
		writer.append(query);
		return true;
	}

	public void setFile(String file) {
		this.file = file;
	}
	
	public String getFile() {
		return file;
	}
	
	public void setWriter(BufferedWriter writer) {
		this.writer = writer;
	}
	
	public BufferedWriter getWriter() {
		return writer;
	}

	@Override
	public boolean close() throws Exception {
		writer.flush();
		writer.close();
		return true;
	}

	@Override
	public boolean open() throws Exception {
		writer = new BufferedWriter(new FileWriter(file, true));
		return true;
	}

	@Override
	public void flush() throws Exception {
		writer.flush();
	}
	
}
